package com.zxgj.datadirect.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zxgj.common.annotation.Log;
import com.zxgj.common.core.controller.BaseController;
import com.zxgj.common.core.domain.AjaxResult;
import com.zxgj.common.enums.BusinessType;
import com.zxgj.datadirect.entity.DataDirectApply;
import com.zxgj.datadirect.service.IDataDirectApplyService;
import com.zxgj.common.utils.poi.ExcelUtil;
import com.zxgj.common.core.page.TableDataInfo;

/**
 * 数据直达基层-申请记录Controller
 * 
 * @author ruoyi
 * @date 2025-08-30
 */
@RestController
@RequestMapping("/datadirect/apply")
public class DataDirectApplyController extends BaseController
{
    @Autowired
    private IDataDirectApplyService dataDirectApplyService;

    /**
     * 查询数据直达基层-申请记录列表
     */
    @PreAuthorize("@ss.hasPermi('datadirect:apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(DataDirectApply dataDirectApply)
    {
        startPage();
        List<DataDirectApply> list = dataDirectApplyService.selectDataDirectApplyList(dataDirectApply);
        return getDataTable(list);
    }

    /**
     * 导出数据直达基层-申请记录列表
     */
    @PreAuthorize("@ss.hasPermi('datadirect:apply:export')")
    @Log(title = "数据直达基层-申请记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DataDirectApply dataDirectApply)
    {
        List<DataDirectApply> list = dataDirectApplyService.selectDataDirectApplyList(dataDirectApply);
        ExcelUtil<DataDirectApply> util = new ExcelUtil<DataDirectApply>(DataDirectApply.class);
        util.exportExcel(response, list, "数据直达基层-申请记录数据");
    }

    /**
     * 获取数据直达基层-申请记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('datadirect:apply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dataDirectApplyService.selectDataDirectApplyById(id));
    }

    /**
     * 新增数据直达基层-申请记录
     */
    @PreAuthorize("@ss.hasPermi('datadirect:apply:add')")
    @Log(title = "数据直达基层-申请记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DataDirectApply dataDirectApply)
    {
        return toAjax(dataDirectApplyService.insertDataDirectApply(dataDirectApply));
    }

    /**
     * 修改数据直达基层-申请记录
     */
    @PreAuthorize("@ss.hasPermi('datadirect:apply:edit')")
    @Log(title = "数据直达基层-申请记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DataDirectApply dataDirectApply)
    {
        return toAjax(dataDirectApplyService.updateDataDirectApply(dataDirectApply));
    }

    /** 
     * 删除数据直达基层-申请记录
     */
    @PreAuthorize("@ss.hasPermi('datadirect:apply:remove')")
    @Log(title = "数据直达基层-申请记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") Long id)
    {
        return toAjax(dataDirectApplyService.deleteDataDirectApplyById(id));
    }

    /**
     * 批量删除数据直达基层-申请记录
     */
    @PreAuthorize("@ss.hasPermi('datadirect:apply:remove')")
    @Log(title = "数据直达基层-申请记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/batch/{ids}")
    public AjaxResult removeBatch(@PathVariable("ids") String ids)
    {
        String[] idArray = ids.split(",");
        Long[] longIds = new Long[idArray.length];
        for (int i = 0; i < idArray.length; i++) {
            longIds[i] = Long.parseLong(idArray[i]);
        }
        return toAjax(dataDirectApplyService.deleteDataDirectApplyByIds(longIds));
    }
}
